package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import map.ScrollMap;
	import instance.GameModel;
	import util.FPSUtil;
	
	[SWF(width="800",height="480",frameRate="100",backgroundColor="0xffffff")]
	public class RunningPanda extends Sprite
	{
		private var scrollMap:ScrollMap;
		
		private var state:int = 0;;
		
		public function RunningPanda()
		{
			stage.align = StageAlign.TOP;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			init();	
			this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			this.addEventListener(MouseEvent.CLICK,onClick);
		}
		
		public function init():void {
			scrollMap = ScrollMap.Instance;
			
			scrollMap.initMap({"mapHeight":480,"mapWidth":800});
			
			scrollMap.initHero();
			
			scrollMap.update();
			
			this.addChild(scrollMap);
			
			this.addChild(new FPSUtil());
		}
		
		public function onClick(evt:MouseEvent):void {
			if(GameModel.instance.hero) {
				GameModel.instance.hero.onStageClick();
			}
		}
		
		public function onKeyDown(evt:KeyboardEvent):void {
			if(evt.keyCode==32) {
				if(state==0) {
					scrollMap.pause();
					state = 1;
				}else {
					scrollMap.update();
					state = 0;
				}
			}
		}
	}
}